//
//  DoorChargesViewController.m
//  CPICApp
//
//  Created by zhiwei li on 13-4-2.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "DoorChargesViewController.h"
#import "RCAlertViewUtil.h"
#import "NSString+SBJson.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "ASIFormDataRequest.h"
#import "Appdelegate.h"

@interface DoorChargesViewController ()

@end

@implementation DoorChargesViewController
@synthesize Goodsname;
@synthesize GoodsPrice;
@synthesize progress;
@synthesize OrderId;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"上门收费");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"上门收费");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"上门收费");        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }
    
    tablegoods = [[UITableView alloc]initWithFrame:CGRectMake(5, 62, self.view.frame.size.width, 200) style:UITableViewStyleGrouped];
	tablegoods.delegate = self;
	tablegoods.dataSource = self;
    
    tablegoods.opaque = NO;
    tablegoods.backgroundView = nil;
    tablegoods.autoresizingMask = UIViewContentModeTop;
    tablegoods.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    tablegoods.scrollEnabled=NO;
    tablegoods.backgroundColor=[UIColor clearColor];
	[self.view addSubview:tablegoods];
    
    tablecustomerinfo = [[UITableView alloc]initWithFrame:CGRectMake(5, 194, self.view.frame.size.width, 250) style:UITableViewStyleGrouped];
	tablecustomerinfo.delegate = self;
	tablecustomerinfo.dataSource = self;
    
    tablecustomerinfo.opaque = NO;
    tablecustomerinfo.backgroundView = nil;
    tablecustomerinfo.autoresizingMask = UIViewContentModeTop;
    tablecustomerinfo.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    tablecustomerinfo.scrollEnabled=NO;
    tablecustomerinfo.backgroundColor=[UIColor clearColor];
	[self.view addSubview:tablecustomerinfo];
    
    //初始化数组
    arrGoods=[[NSMutableArray alloc]initWithObjects:@"产品名称:",@"产品价格:", nil];
    arrCustomer=[[NSMutableArray alloc]initWithObjects:@"联系人:",@"联系电话:",@"联系地址:",@"目前太保移动终端'礼品秒杀'功能仅面向通讯地址为深圳市的车主,非深圳市地区暂未开通!", nil];
    
    UIButton * DoorChargesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [DoorChargesBtn setImage:[UIImage imageNamed:@"Submit_suggestion.png"] forState:UIControlStateNormal];
    [DoorChargesBtn setTitle:@"提交" forState:UIControlStateNormal];
    DoorChargesBtn.frame=CGRectMake(86, 392, 310/2, 119/2);
    [DoorChargesBtn addTarget:self action:@selector(submitinfo) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:DoorChargesBtn];
    
    UILabel * lbSuggestion = [[UILabel alloc]initWithFrame:CGRectMake(86, 380, 310/2, 119/2)];
    lbSuggestion.text = @"提交";
    lbSuggestion.textAlignment = UITextAlignmentCenter;
    lbSuggestion.textColor = [UIColor whiteColor];
    lbSuggestion.backgroundColor = [UIColor clearColor];
    [self.view addSubview:lbSuggestion];
    [lbSuggestion release];
}

-(void) submitinfo
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bSeckillArea=TRUE;
    
    if (txtCustomerName.text.length == 0)
    {
        [self justShowMessage:@"联系人名称不能为空" title:@"提示!"];
        return;
    }
    
    if (txtCustomerPhone.text.length == 0) 
    {
        [self justShowMessage:@"联系人手机号码不能为空" title:@"提示!"];
        return;
    }
    
    if (txtCustomerAddress.text.length == 0) 
    {
        [self justShowMessage:@"联系人地址不能为空" title:@"提示!"];
        return;
    }
    
    NSString * Mobile = txtCustomerPhone.text;
    if (![self isValidateMobile:Mobile])
    {
        [self justShowMessage:@"非法的手机号码,请输入正确的手机号码" title:@""];
        return;
    }

    
    [self setDoorChargesRequest];
}

#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView==tablegoods)
    {
        return [arrGoods count];
    }
    else
    {
        return [arrCustomer count];
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary * DictCustomerInfo =[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CUSTOMER_INFO];
    if (DictCustomerInfo!=nil) 
    {
        
        if ([DictCustomerInfo valueForKey:@"userName"])
        {
            NSLog(@"%@",[DictCustomerInfo valueForKey:@"userName"]);
        }
        else 
        {
            //[self justShowMessage:@"请到客户资料管理填写客户名称!" title:@"提示"];
        }
        
        if ([DictCustomerInfo valueForKey:@"phone"])
        {
            //NSLog(@"%@",[DictCustomerInfo valueForKey:@"phone"]);
        }
        else 
        {
            //[self justShowMessage:@"请到客户资料管理填写手机号码!" title:@"提示"];
        }
        
        if ([DictCustomerInfo valueForKey:@"postalAddress"])
        {
            NSLog(@"%@",[DictCustomerInfo valueForKey:@"postalAddress"]);
        }
        else 
        {
            //[self justShowMessage:@"请到客户资料管理填写联系地址!" title:@"提示"];
        }
    }
    else
    {
        //[self justShowMessage:@"用户还没补充完整客户名称、手机号码、联系地址!" title:@"注意"];
    }

    if(tableView==tablegoods)
    {
        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[tablegoods dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;//选中后颜色没变化
            
            if(indexPath.row==0)
            {
                UILabel *lblGoodsName=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 100, 21)];
                lblGoodsName.backgroundColor=[UIColor clearColor];
                lblGoodsName.text=[arrGoods objectAtIndex:indexPath.row];
                lblGoodsName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblGoodsName];
                [lblGoodsName release];
                
                UITextField * txtGoodsName=[[UITextField alloc]initWithFrame:CGRectMake(125, 9.5, 170, 31)];
                txtGoodsName.borderStyle=UITextBorderStyleNone;
                txtGoodsName.returnKeyType=UIReturnKeyDone;
                txtGoodsName.enabled=NO;
                txtGoodsName.delegate = self;
                txtGoodsName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtGoodsName];
                txtGoodsName.placeholder = self.Goodsname;
                [txtGoodsName release];
            }
            else if(indexPath.row==1)
            {
                UILabel *lblGoodsSeckillTime=[[UILabel alloc]initWithFrame:CGRectMake(15,9.5, 110, 21)];
                lblGoodsSeckillTime.backgroundColor=[UIColor clearColor];
                lblGoodsSeckillTime.text=[arrGoods objectAtIndex:indexPath.row];
                lblGoodsSeckillTime.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblGoodsSeckillTime];
                [lblGoodsSeckillTime release];
                
                UITextField *txtGoodsSeckillTime=[[UITextField alloc]initWithFrame:CGRectMake(125, 9.5, 170, 31)];
                txtGoodsSeckillTime.borderStyle=UITextBorderStyleNone;
                txtGoodsSeckillTime.returnKeyType=UIReturnKeyDone;
                txtGoodsSeckillTime.delegate = self;
                txtGoodsSeckillTime.enabled=NO;
                txtGoodsSeckillTime.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtGoodsSeckillTime];
                txtGoodsSeckillTime.placeholder = self.GoodsPrice;
                [txtGoodsSeckillTime release];
            }
        }
        return cell;
    }
    else
    {
        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[tablecustomerinfo dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            UIButton * Remindbtn = [UIButton buttonWithType:UIButtonTypeInfoDark];
            Remindbtn.frame = CGRectMake(85, 7, 18, 19);
            [Remindbtn addTarget:self action:@selector(remindclick:) forControlEvents:UIControlEventTouchUpInside];
            if (indexPath.row!=3) {
                [cell addSubview:Remindbtn];
            }

            
            if(indexPath.row==0)
            {
                UILabel *lblCustomerName=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 116, 21)];
                lblCustomerName.backgroundColor=[UIColor clearColor];
                lblCustomerName.text=[arrCustomer objectAtIndex:indexPath.row];
                lblCustomerName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblCustomerName];
                [lblCustomerName release];
                
                txtCustomerName=[[UITextField alloc]initWithFrame:CGRectMake(110, 4.5, 148, 31)];
                txtCustomerName.borderStyle=UITextBorderStyleLine;
                txtCustomerName.returnKeyType=UIReturnKeyDone;
                txtCustomerName.delegate=self;
                txtCustomerName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtCustomerName];
                txtCustomerName.text = [DictCustomerInfo valueForKey:@"userName"];
                Remindbtn.tag=0;
            }
            else if(indexPath.row==1)
            {
                UILabel *lblCustomerPhone=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 119, 21)];
                lblCustomerPhone.backgroundColor=[UIColor clearColor];
                lblCustomerPhone.text=[arrCustomer objectAtIndex:indexPath.row];
                lblCustomerPhone.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblCustomerPhone];
                [lblCustomerPhone release];
                
                txtCustomerPhone=[[UITextField alloc]initWithFrame:CGRectMake(110, 4.5, 148, 31)];
                txtCustomerPhone.borderStyle=UITextBorderStyleLine;
                txtCustomerPhone.returnKeyType=UIReturnKeyDone;
                
                CustomNumbleKeyboardView *customKeyboardView = [[CustomNumbleKeyboardView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 238)];
                customKeyboardView.delegate = self;
                [txtCustomerPhone setInputView:customKeyboardView];
                txtCustomerPhone.delegate=self;
                txtCustomerPhone.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtCustomerPhone];
                txtCustomerPhone.text = [DictCustomerInfo valueForKey:@"phone"];
                Remindbtn.tag=1;
            }
            else if(indexPath.row==2)
            {
                UILabel *lblCustomerAddress=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 120, 21)];
                lblCustomerAddress.backgroundColor=[UIColor clearColor];
                lblCustomerAddress.text=[arrCustomer objectAtIndex:indexPath.row];
                lblCustomerAddress.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblCustomerAddress];
                [lblCustomerAddress release];
                
                txtCustomerAddress=[[UITextField alloc]initWithFrame:CGRectMake(110, 4.5, 180, 31)];
                txtCustomerAddress.borderStyle=UITextBorderStyleLine;
                txtCustomerAddress.returnKeyType=UIReturnKeyDone;
                txtCustomerAddress.delegate =self;
                txtCustomerAddress.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtCustomerAddress];
                txtCustomerAddress.text = [DictCustomerInfo valueForKey:@"postalAddress"];
                [txtCustomerAddress release];
                Remindbtn.tag=2;
            }
            else if(indexPath.row==3)
            {
                UITextView *txvNotice=[[UITextView alloc]initWithFrame:CGRectMake(15, 0, 300, 50)];
                txvNotice.backgroundColor=[UIColor clearColor];
                txvNotice.text=[arrCustomer objectAtIndex:indexPath.row];
                txvNotice.font = [UIFont systemFontOfSize:12.0];
                txvNotice.textColor=[UIColor redColor];
                txvNotice.editable=NO;
                [cell addSubview:txvNotice];
                [txvNotice release];
            }
        }
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(void) remindclick:(id)sender
{
    UIButton *button = (UIButton *)sender;
    if (button.tag==0) {
        [self justShowMessage:@"仅作为参与我司客户活动中奖后寄送相应礼品时所必需" title:@"提示"];
    }
    else if(button.tag==1)
    {
         [self justShowMessage:@"仅作为参与我司客户活动中奖后寄送相应礼品时所必需" title:@"提示"];
    }
    else if(button.tag==2)
    {
        [self justShowMessage:@"仅作为参与我司客户活动中奖后寄送相应礼品时所必需" title:@"提示"];
    }
}

//数字键盘
- (void)numberKeyBoardInput:(NSInteger) number
{
    NSMutableString *textString = [[[NSMutableString alloc] initWithFormat:@"%@%d",txtCustomerPhone.text,number] autorelease];
    if ([textString length]>11)
    {
        [self justShowMessage:@"手机号码输入不能超过11位!" title:@""];
        return;
    }
    txtCustomerPhone.text = textString;
}

- (void)numberKeyBoardBackspace
{
    NSMutableString* mutableString = [[[NSMutableString alloc] initWithFormat:@"%@", txtCustomerPhone.text] autorelease];
    if ([mutableString length] >=1) {
        NSRange tmpRange;
        tmpRange.location = [mutableString length] - 1;
        tmpRange.length = 1;
        [mutableString deleteCharactersInRange:tmpRange];
    }
    txtCustomerPhone.text = mutableString;
    
}

- (void)numberKeyBoardFinish
{
    [txtCustomerPhone resignFirstResponder];
}


-(id) initView:(NSString *)goodsname withgoodsprice:(NSString *)goodsprice withOrderid:(NSString *)orderid
{
    self.OrderId = orderid;
    self.Goodsname = goodsname;
    self.GoodsPrice = goodsprice;
    self = [super init];
    return self;
}

-(void) ClickCallOutBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)setDoorChargesRequest///向太保移动平台发送上门收费请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
//        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
//        return;
    }
    
    NSString * useraccount;
    if ([dictUserInfo valueForKey:@"UserAccount"]) {
        useraccount = [dictUserInfo valueForKey:@"UserAccount"];
    }
    else
    {
        useraccount=@"cpic";
    }
    //NSString *StrRequestCode=@"RequestCode=50406";
    NSString *StrRequestData=[NSString stringWithFormat:@"{\"orderID\":\"%@\",\"postalAddress\":\"%@\",\"userAccount\":\"%@\",\"userName\":\"%@\",\"userPhone\":\"%@\"}",self.OrderId,txtCustomerAddress.text,useraccount,txtCustomerName.text,txtCustomerPhone.text];
    NSLog(@"上门收费报文%@",StrRequestData);
   // NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,StrRequestCode,StrRequestData];
    //NSLog(@"++++++++++++++%@",strUrl);
   // NSString *StrUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
    
    //NSLog(@"22222222222222%@",StrUrl);
    
    //NSURL *Myurl = [NSURL URLWithString:StrUrl];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
    //NSLog(@"URL:%@",Myurl);
    ASIFormDataRequest *requestthree = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [requestthree setPostValue:@"50406" forKey:@"RequestCode"];
    [requestthree setPostValue:StrRequestData forKey:@"RequestData"];
    
    [requestthree setDelegate:self];
    [requestthree setDidFailSelector:@selector(ResponseFailthree:)];
    [requestthree setDidFinishSelector:@selector(ResonseSuccessthree:)];
    [requestthree startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccessthree:(ASIHTTPRequest *)requestthree
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSString *responseString = [requestthree responseString];
    NSLog(@"responseString====%@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse======%@",dictResponse);
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        [self justShowMessage:@"订单已生效,请注意收货!" title:@"提示"];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    else
    {
        [self justShowMessage:@"提交失败！" title:@"提示"];
    }
}

- (void)ResponseFailthree:(ASIHTTPRequest *)requestthree
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if(textField==txtCustomerName||textField == txtCustomerPhone)
    {
        [self SetAnimation:80];
    }
    else if(textField == txtCustomerAddress)
    {
        [self SetAnimation:120];
    }
    
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField==txtCustomerName||textField == txtCustomerPhone)
    {
        [self backAnimation:80];
    }
    else if(textField == txtCustomerAddress)
    {
        [self backAnimation:120];
    }
}

-(void)SetAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x+=Xorigin;
    frame.origin.y-=Xorigin;
    //frame.size.height +=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
}

-(void)backAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x -=Xorigin;
    frame.origin.y+=Xorigin;
    //frame.size.height -=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
    // [textField resignFirstResponder];
}

/*手机号码验证*/
-(BOOL) isValidateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    [tablegoods release];
    [tablecustomerinfo release];
    [GoodsPrice release];
    [Goodsname release];
    [progress release];
    [OrderId release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
